module et {
    export class Action {
        private actions = new Array<[() => void, any]>();
        public Add(func: () => void, target?: any) {
            this.actions.Add([func, target]);
        }
        public Remove(func: () => void) {
            let index = this.actions.findIndex(a => a[0] == func);
            if (index >= 0)
                this.actions.RemoveAt(index);
        }
        public Clear() {
            this.actions.length = 0;
        }
        public Invoke() {
            for (const func of this.actions) {
                func[0].call(func[1]);
            }
        }
    }
    export class Action1<T1> {
        private actions = new Array<[(t1: T1) => void, any]>();
        public Add(func: (t1: T1) => void, target?: any) {
            this.actions.Add([func, target]);
        }
        public Remove(func: (t1: T1) => void) {
            let index = this.actions.findIndex(a => a[0] == func);
            if (index >= 0)
                this.actions.RemoveAt(index);
        }
        public Clear() {
            this.actions.length = 0;
        }
        public Invoke(t1: T1) {
            for (const func of this.actions) {
                func[0].call(func[1], t1);
            }
        }
    }
    export class Action2<T1, T2> {
        private actions = new Array<[(t1: T1, t2: T2) => void, any]>();
        public Add(func: (t1: T1, t2: T2) => void, target?: any) {
            this.actions.Add([func, target]);
        }
        public Remove(func: (t1: T1, t2: T2) => void) {
            let index = this.actions.findIndex(a => a[0] == func);
            if (index >= 0)
                this.actions.RemoveAt(index);
        }
        public Clear() {
            this.actions.length = 0;
        }
        public Invoke(t1: T1, t2: T2) {
            for (const func of this.actions) {
                func[0].call(func[1], t1, t2);
            }
        }
    }
    export class Action3<T1, T2, T3> {
        private actions = new Array<[(t1: T1, t2: T2, t3: T3) => void, any]>();
        public Add(func: (t1: T1, t2: T2, t3: T3) => void, target?: any) {
            this.actions.Add([func, target]);
        }
        public Remove(func: (t1: T1, t2: T2, t3: T3) => void) {
            let index = this.actions.findIndex(a => a[0] == func);
            if (index >= 0)
                this.actions.RemoveAt(index);
        }
        public Clear() {
            this.actions.length = 0;
        }
        public Invoke(t1: T1, t2: T2, t3: T3) {
            for (const func of this.actions) {
                func[0].call(func[1], t1, t2, t3);
            }
        }
    }
}